package cn.yunhe.servlet;

import cn.yunhe.pojo.UserDemo;
import cn.yunhe.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/RegistUserNameServlet")
public class RegistUserNameServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        String name  =    request.getParameter("username");
       if(name != ""){
           UserService userService = new UserService();
           UserDemo userdemo =  userService.loginSearchByName(name);
           if(userdemo != null){
               out.print("此用户已经存在");
           }else{
               out.print("此用户可以正常使用");
           }
       }else{
           out.print("用户名不能为空");
       }

    }
}
